import React from 'react';
import { useTranslation } from 'react-i18next';
import { Button, InputItem ,Toast} from 'antd-mobile';
import { createForm } from 'rc-form';
import service from '@/api/apis.js';
const Login = props => {
    let { t, i18n } = useTranslation();
    const { getFieldProps, validateFields } = props.form;
    const handleLogin = () => {
        validateFields((error, value) => {
            if (!error) {
                service.login(value).then(res => {
                    console.log(res)
                   Toast.success(res.message,3)
                });
            }
        });
    };
    return (
        <div>
            <div>
                <Button onClick={() => i18n.changeLanguage(i18n.language == 'en' ? 'zh' : 'en')}>
                    {i18n.language == 'en' ? 'zh' : 'en'}
                </Button>
            </div>
            <InputItem {...getFieldProps('staffCode')} clear placeholder={t('username')} />
            <InputItem {...getFieldProps('password')} clear type="password" placeholder={t('password')} />
            <Button type="primary" onClick={() => handleLogin()}>
                {t('login_btn')}
            </Button>
        </div>
    );
};

export default createForm()(Login);
